package com.company.controller;

import com.company.model.User;
import com.company.service.LoginService;
import com.company.utils.MessageResponse;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@CrossOrigin(origins = "http://localhost:8080")
public class UserController {

    @GetMapping("/user/{name}")
    public MessageResponse<Boolean> hasUser(@PathVariable String name) {
        return LoginService.hasUser(name);
    }

    @DeleteMapping("/login/user")
    public MessageResponse<Boolean> exit(HttpSession session) {
        return LoginService.exit(session);
    }

    @PostMapping("/register/user")
    public MessageResponse<Boolean> register(@RequestBody User user) {
        return LoginService.register(user);
    }

}
